package com.yuwei.module_visit.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.vm.BaseViewModel2
import com.yuwei.http.entity.AddVisitEntity
import com.yuwei.http.entity.VisitEntity
import com.yuwei.module_visit.model.VisitRepository
import kotlinx.coroutines.launch

class VisitViewModel: BaseViewModel2<VisitRepository>() {
    override fun createRepository(): VisitRepository = VisitRepository()
    val getVisitListSuccess by lazy { MutableLiveData<VisitEntity>() }
    val addVisitSuccess by lazy { MutableLiveData<AddVisitEntity>() }
    fun getVisitList() {
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getVisitList()
            if (result.code == 200){
                getVisitListSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue(result.message)
            }
        }
    }
    fun addVisit(addVisitEntity: AddVisitEntity) {
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.addVisit(addVisitEntity)
            if (result.code == 200){
                addVisitSuccess.postValue(result.data)
            }else{
                mErrorLiveData.postValue(result.message)
            }
        }
    }
}